# -*- coding: utf-8 -*- 

'''
Created on 2013.6.29
记录note模块，负责查询所有的，更新的，保存新的note

@author: lzy
'''
import logging
import datetime
from framework.bottle import Bottle,redirect,request
from jinja2.environment import Environment
from jinja2.loaders import FileSystemLoader
from db.NoteDO import Note
from db.NoteDAO import NoteDAO
from framework.gaesessions import get_current_session

#jinja2
env = Environment(loader = FileSystemLoader('static/templates'))
recordController = Bottle()
        
@recordController.route('/index.html')    
def get_records():
    session = get_current_session()
    username = "default"
    if session.has_key('username'):  
        username = session['username']
        
    template = env.get_template('record.html')
    return template.render(username=username)

@recordController.route('/save', method='POST')
def save_record():
    content = request.forms.get('content')
    tags = request.forms.get('t ag')
    logging.info(content)
    
    note = Note()
    note.content = content
    note.gmt_create = datetime.datetime.now().date()
    note.gmt_modified = datetime.datetime.now().date()
    note.tag = tags
    note.operator = 'lzy'
    
    NoteDAO.save(note)



    
        
    